#ifndef _UART_H_
#define _UART_H_
#include "system.h"
#include <stdarg.h>

#define Uart1_RxPin GPIO_Pin_10
#define Uart1_TxPin GPIO_Pin_9
#define Uart2_RxPin GPIO_Pin_3
#define Uart2_TxPin GPIO_Pin_2
#define Uart3_RxPin GPIO_Pin_11
#define Uart3_TxPin GPIO_Pin_10
#define Uart4_RxPin GPIO_Pin_11
#define Uart4_TxPin GPIO_Pin_10


#define MAX_DEBUG_RX_LEN 512
#define MAX_WIFI_RX_LEN 512
#define MAX_485_RX_LEN 64
#define MAX_SOUND_RX_LEN 200
#define DEBUG_UART USART1
#define WIFI_UART USART2
#define RS485_UART USART3
#define SOUND_UART UART4
extern u8 u8_acDebugUartRxBuf[MAX_DEBUG_RX_LEN];
extern u16 u16_gDebugUartRxLen;

extern u8 u8_485UartRxBuf[MAX_485_RX_LEN];
extern u8 ac485UartRxComplete;
extern u16 u16_g485UartRxLen;

extern u8 u8_acWifiUartRxBuf[MAX_WIFI_RX_LEN];
extern u8 acWifiUartRxComplete;
extern u16 u16_gWifiUartRxLen;

extern u8 u8_SoundUartRxBuf[MAX_SOUND_RX_LEN];
extern u8 acSoundUartRxComplete;
extern u16 u16_gSoundUartRxLen;
extern uint8_t Serial_RxFlag;
extern uint8_t Config_AT_mode;

typedef enum
{
    BaudRate2400 = 2400,
    BaudRate4800 = 4800,
    BaudRate9600 = 9600,
    BaudRate57600 = 57600
} BaudRate_t;
typedef enum
{
    STATE_IDLE,
    STATE_RECEIVING,
    STATE_COMPLETE
} RECE_STATUS_T;
typedef enum
{
    NO_REC,
    REC

} FLAG_STATUS_T;
#if ELECT
void uart_init(void);
void vBsp_USARTDeinit(USART_TypeDef *uart);
void uart_send_byte(u8 byte, USART_TypeDef *uart);
void uart_send_string(u8 str[], USART_TypeDef *uart);
void uart_send_hex_num(u8 hexBuff[], u16 len,USART_TypeDef *uart);
u16 uart_get_string(u8 buf[], u16 len, USART_TypeDef *uart);
int fputc(int ch, FILE *f);
void uart_printf(char *format, ...);
void uart_SendNumber(uint32_t Number, uint8_t Length, USART_TypeDef *uart);
FLAG_STATUS_T Serial_GetRxFlag(void);
#endif
typedef void(*pUartInit)(void);
typedef void(*pUartDeinit)(USART_TypeDef *);
typedef void(*pUartSendByte)(u8,USART_TypeDef *);
typedef void(*pUartSendString)(u8 *,USART_TypeDef *);
typedef void(*pUartSendHex)(u8 *,u16,USART_TypeDef *);
typedef void(*pUartSendNumber)(uint32_t , uint8_t , USART_TypeDef *);
typedef void(*pUartDBG)(char *,...);
typedef struct 
{
    /* data */
    pUartInit           PuartInit;
    pUartDeinit         PuartDeinit;
    pUartSendByte       PuartSendByte;
    pUartSendString     PuartSendString;
    pUartSendHex        PuartSendHex;
    pUartSendNumber     PuartSendNumber;
    pUartDBG            PuartDBG;
}uart_t;
uart_t *uartCreate(void);

#endif
